/*
 * 1.4
 * Write a method to decide if two strings are anagrams or not.
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int comp(const void *a, const void *b)
{
    // XXX: note the conversion
    return *(const char *)(a) < *(const char *)(b);
}

bool anagram(const char *str1, const char *str2)
{
    int len1 = strlen(str1);
    int len2 = strlen(str2);
    if (len1 != len2) {
        return false;
    }
    char *s1 = strdup(str1);
    char *s2 = strdup(str2);
    qsort(s1, strlen(s1), 1, comp);
    qsort(s2, strlen(s2), 1, comp);
    bool b = memcmp(s1, s2, len1) == 0;
    free(s1);
    free(s2);
    return b;
}

int main()
{
    bool b1 = anagram("1234", "4321");
    bool b2 = anagram("112223", "121322");
    printf("b1=%d,b2=%d\n", b1, b2);
}
